//
//  TemplateFoundDetailsDHTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/7/18.
//

#import "TemplateFoundDetailsDHTableViewCell.h"

@interface TemplateFoundDetailsDHTableViewCell ()<UITextViewDelegate>

///必填
@property (nonatomic ,strong) UILabel * forceFlag;
@property (nonatomic ,strong) UILabel * name;
@property (nonatomic ,strong) UILabel * StrLab;
@property (nonatomic ,strong) IQTextView * textview;


@end
@implementation TemplateFoundDetailsDHTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     if (self)
     {
          [self setupView];
     }
     return self;
}


- (void)setupView{
     
     self.backgroundColor = UIColor.clearColor;
     self.contentView.backgroundColor = UIColor.whiteColor;
     self.userInteractionEnabled = YES;
     self.contentView.userInteractionEnabled = YES;
     
     UIView * makeview = [UIView new];
     makeview.backgroundColor = KcolorHex(@"#F6F7F9");
     [DTKTool YJ:kwt(5) andView:makeview];
     [self.contentView addSubview:makeview];
     [makeview mas_makeConstraints:^(MASConstraintMaker *make) {
          make.top.offset(0);
          make.bottom.right.offset(kwt(-10));
          make.left.offset(kwt(10));
     }];
     
     UILabel * forceFlag= [DTKTool labelWithText:@"*" andFont:kCFont(18) andTextColor:KcolorHex(@"#FA0F0F")];
     [makeview addSubview:forceFlag];
     self.forceFlag = forceFlag;
     [forceFlag mas_makeConstraints:^(MASConstraintMaker *make) {
          make.left.offset(kwt(12));
          make.top.offset(kwt(14));
     }];
     
     
     UILabel * name = [DTKTool labelWithText:@"--" andFont:kCFont(18) andTextColor:KcolorHex(@"#222222")];
     [makeview addSubview:name];
     self.name = name;
     [name mas_makeConstraints:^(MASConstraintMaker *make) {
          make.left.equalTo(forceFlag.mas_right);
          make.top.offset(kwt(14));
     }];
     
     UILabel * StrLab = [DTKTool labelWithText:@"0/140" andFont:kFont(17) andTextColor:KcolorHex(@"#787A79")];
     [makeview addSubview:StrLab];
     self.StrLab = StrLab;
     [StrLab mas_makeConstraints:^(MASConstraintMaker *make) {
          make.right.offset(kwt(-12));
          make.centerY.equalTo(name);
     }];
     
     UIView * line = [UIView new];
     line.backgroundColor = KcolorHex(@"#DBDBDB");
     [makeview addSubview:line];
     [line mas_makeConstraints:^(MASConstraintMaker *make) {
          make.left.offset(kwt(10));
          make.right.offset(kwt(-10));
          make.top.offset(kwt(40));
          make.height.offset(0.5);
     }];
     
     
     IQTextView * textview = [IQTextView new];
     textview.textColor = KcolorHex(@"#222222");
     textview.font = kFont(17);
     textview.delegate = self;
     textview.backgroundColor = UIColor.clearColor;
     self.textview = textview;
     [makeview addSubview:textview];
     [textview mas_makeConstraints:^(MASConstraintMaker *make) {
          make.left.offset(kwt(10));
          make.right.offset(kwt(-10));
          make.top.offset(kwt(50));
          make.bottom.offset(kwt(-10));
     }];
}

- (void)setModel:(TemplateFoundDetailsTaskItemModelListModel *)model{
     _model = model;
     ///forceFlag 是否必填
     self.forceFlag.text = (model.forceFlag == 1)? @"*":@"";
     self.name.text = model.name;
     self.StrLab.text = [NSString stringWithFormat:@"%lu/140",(unsigned long)model.content.length];
     self.textview.text = model.content;
     
}
-(void)textViewDidChange:(UITextView *)textView{
     if(textView.text.length > 140){
          textView.text = [textView.text substringToIndex:140];
     }
     self.StrLab.text = [NSString stringWithFormat:@"%lu/140",(unsigned long)textView.text.length];
}
- (void)textViewDidEndEditing:(UITextView *)textView {
     self.model.content = textView.text;
}
@end
@interface TemplateFoundDetailsDHView ()<UITextViewDelegate>

///必填
@property (nonatomic ,strong) UILabel * forceFlag;
@property (nonatomic ,strong) UILabel * name;
@property (nonatomic ,strong) IQTextView * textview;
@property (nonatomic ,strong) UILabel * StrLab;
@end
@implementation TemplateFoundDetailsDHView
+ (instancetype)NewView{
     TemplateFoundDetailsDHView * view = [TemplateFoundDetailsDHView new];
     [view setupView];
     return view;
}
-  (void)setupView{
     UIView * makeview = [UIView new];
     makeview.backgroundColor = KcolorHex(@"#F6F7F9");
     [DTKTool YJ:kwt(5) andView:makeview];
     [self addSubview:makeview];
     [makeview mas_makeConstraints:^(MASConstraintMaker *make) {
          make.top.left.right.offset(0);
          make.bottom.offset(kwt(-10));
     }];
     
     UILabel * forceFlag= [DTKTool labelWithText:@"*" andFont:kCFont(18) andTextColor:KcolorHex(@"#FA0F0F")];
     [makeview addSubview:forceFlag];
     self.forceFlag = forceFlag;
     [forceFlag mas_makeConstraints:^(MASConstraintMaker *make) {
          make.left.offset(kwt(12));
          make.top.offset(kwt(14));
     }];
     
     
     UILabel * name = [DTKTool labelWithText:@"--" andFont:kCFont(18) andTextColor:KcolorHex(@"#222222")];
     [makeview addSubview:name];
     self.name = name;
     [name mas_makeConstraints:^(MASConstraintMaker *make) {
          make.left.equalTo(forceFlag.mas_right);
          make.top.offset(kwt(14));
     }];
     
     UIView * line = [UIView new];
     line.backgroundColor = KcolorHex(@"#DBDBDB");
     [makeview addSubview:line];
     [line mas_makeConstraints:^(MASConstraintMaker *make) {
          make.left.offset(kwt(10));
          make.right.offset(kwt(-10));
          make.top.offset(kwt(40));
          make.height.offset(0.5);
     }];
     
     UILabel * StrLab = [DTKTool labelWithText:@"0/140" andFont:kFont(17) andTextColor:KcolorHex(@"#787A79")];
     [makeview addSubview:StrLab];
     self.StrLab = StrLab;
     [StrLab mas_makeConstraints:^(MASConstraintMaker *make) {
         make.right.offset(kwt(-12));
         make.centerY.equalTo(name);
     }];
     
     IQTextView * textview = [IQTextView new];
     textview.textColor = KcolorHex(@"#222222");
     textview.font = kFont(17);
     textview.delegate = self;
     textview.backgroundColor = UIColor.clearColor;
     self.textview = textview;
     [makeview addSubview:textview];
     [textview mas_makeConstraints:^(MASConstraintMaker *make) {
          make.left.offset(kwt(10));
          make.right.offset(kwt(-10));
          make.top.offset(kwt(50));
          make.bottom.offset(kwt(-10));
     }];
}
- (void)setModel:(TemplateFoundDetailsTaskItemModelListModel *)model{
     _model = model;
     ///forceFlag 是否必填
     self.forceFlag.text = (model.forceFlag == 1)? @"*":@"";
     self.name.text = model.name;
     self.textview.text = model.content;
     self.StrLab.text = [NSString stringWithFormat:@"%lu/140",(unsigned long)model.content.length];

}

-(void)textViewDidChange:(UITextView *)textView{
    if(textView.text.length > 140){
        textView.text = [textView.text substringToIndex:140];
    }
    self.StrLab.text = [NSString stringWithFormat:@"%lu/140",(unsigned long)textView.text.length];
}
- (void)textViewDidEndEditing:(UITextView *)textView {
     self.model.content = textView.text;
}
@end
